package com.example.intermediate.service;

import org.eclipse.paho.client.mqttv3.MqttClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class MqttSubscribeService {

    @Autowired
    private MqttClient mqttClient;

    @Value("${mqtt.topic}")
    private String topic;

    @Value("${mqtt.qos}")
    private int qos;

    public void subscribe() throws Exception {
        mqttClient.subscribe(topic, qos);
        System.out.println("已订阅主题：" + topic);
    }
}
